import 'dart:convert';

import 'package:flutter/foundation.dart';

abstract class BaseModel {
  // json转对象
  Factory<BaseModel> fromJson(Map<String, Object?> item);

  // 按照条件查找，返回第一条数据
  Factory<BaseModel> find(Map<String, Object?>? query, {String sortBy = ''});

  // 按照条件查找，返回符合条件的数据
  Factory<List<BaseModel>> findAll(
    Map<String, Object?>? query, {
    String sortBy = '',
    int offset = 0,
    int limit = -1,
  });

  // 转换为json
  Map<String, Object?> toJson();

  // 插入数据库
  bool insert();

  @override
  String toString() {
    return json.encode(toJson());
  }
}
